package com.example.demo.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyClient {

    public static void main(String[] args) {
        Person proxy = (Person)Proxy.newProxyInstance(Person.class.getClassLoader(), new Class[]{Person.class}, new PersonInvocationHandler());
        proxy.say("你好");
    }

    public static class PersonInvocationHandler implements InvocationHandler {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            System.out.println("这里执行了代理的方法");
            return "aaa";
        }
    }

    public static interface Person {

        void say(String msg);
    }
}
